package com.simple.datax.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.simple.datax.bo.IDataxDictionaryBO;
import com.simple.datax.bo.IDataxReceiveChannelBO;
import com.simple.datax.vo.DataxReceiveChannelVO;
import com.simple.util.common.Constants;
import com.simple.util.common.Utils;
import com.simple.util.object.PageInfoBean;

@Controller 
public class ReceiveChannelController extends AbstractDataxBaseController{
	private final static String JSP_PATH = "_ReceiveChannel";
	
	/** The LOG. */
	private static Logger LOG = Logger.getLogger(ReceiveChannelController.class);
	
	@Autowired
	private IDataxReceiveChannelBO dataxReceiveChannelBO;
	
	@Autowired
	private IDataxDictionaryBO dataxDictionaryBO;

	@RequestMapping("/receiveChannel")  
    public String init(@RequestParam(value="pageNo",required=false,defaultValue="1") Integer pageNo,
			   @RequestParam(value="fiIdSelect",required=false) String fiIdSelect,
			   @RequestParam(value="fcCommunTypeSelect",required=false) String fcCommunTypeSelect,
			   @RequestParam(value="fcMsgFormateIdSelect",required=false) String fcMsgFormateIdSelect,
			   @RequestParam(value="fcMsgTypeSelect",required=false) String fcMsgTypeSelect,
			   final HttpServletRequest request, final HttpServletResponse response)  {
		LOG.debug("Into ReceiveChannelController.init");
		Map<String, String> optionCommunTypeMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_TRANSFERSWAY);
        request.setAttribute("optionCommunTypeMap", optionCommunTypeMap);
        
        Map<String, String> optionMsgTypeMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGETYPE);
        request.setAttribute("optionMsgTypeMap", optionMsgTypeMap);
        
        Map<String, String> optionMsgFormatMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGEFORMAT);
        request.setAttribute("optionMsgFormatMap", optionMsgFormatMap);
        
        Map<String, String> optionMsgCharsetMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGECHARACTER);
        request.setAttribute("optionMsgCharsetMap", optionMsgCharsetMap);
        
        Map<String, String> optionFiFlagMap = Constants.STATE_MAP;
        request.setAttribute("optionFiFlagMap", optionFiFlagMap);

		final PageInfoBean pageInfoBean = new PageInfoBean(pageNo);
        final List<DataxReceiveChannelVO> ls = dataxReceiveChannelBO.findDataxReceiveChannelVOByPage(pageInfoBean, fiIdSelect, fcCommunTypeSelect, fcMsgFormateIdSelect, fcMsgTypeSelect);
        request.setAttribute("dataxReceiveChannelVOList", ls);
        
		final String pageInfo = super.generatePageInfo(request,response,pageInfoBean, "goPage");
	    request.setAttribute("pageInfo", pageInfo);  
        request.setAttribute("pageNo", pageNo);
        
        request.setAttribute("fiIdSelect", fiIdSelect);
        request.setAttribute("fcCommunTypeSelect", fcCommunTypeSelect);
        request.setAttribute("fcMsgFormateIdSelect", fcMsgFormateIdSelect);
        request.setAttribute("fcMsgTypeSelect", fcMsgTypeSelect);
        
        return getJspPath("receive_channel");
    }
	
	@RequestMapping("/receiveChannelAdd")  
    public String add(@RequestParam(value="pageNo",required=false,defaultValue="1") Integer pageNo,
			   @RequestParam(value="fiIdSelect",required=false) String fiIdSelect,
			   @RequestParam(value="fcCommunTypeSelect",required=false) String fcCommunTypeSelect,
			   @RequestParam(value="fcMsgFormateIdSelect",required=false) String fcMsgFormateIdSelect,
			   @RequestParam(value="fcMsgTypeSelect",required=false) String fcMsgTypeSelect,
    		final HttpServletRequest request, final HttpServletResponse response)  {
		LOG.debug("Into ReceiveChannelController.receiveChannelAddInit");

		Map<String, String> optionCommunTypeMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_TRANSFERSWAY);
        request.setAttribute("optionCommunTypeMap", optionCommunTypeMap);
        
        Map<String, String> optionMsgTypeMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGETYPE);
        request.setAttribute("optionMsgTypeMap", optionMsgTypeMap);
        
        Map<String, String> optionMsgFormatMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGEFORMAT);
        request.setAttribute("optionMsgFormatMap", optionMsgFormatMap);
        
        Map<String, String> optionMsgCharsetMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGECHARACTER);
        request.setAttribute("optionMsgCharsetMap", optionMsgCharsetMap);
        
        Map<String, String> optionFiFlagMap = Constants.STATE_MAP;
        request.setAttribute("optionFiFlagMap", optionFiFlagMap);
       
        request.setAttribute("fiId", dataxReceiveChannelBO.generateId());
        request.setAttribute("pageNo", pageNo);
        request.setAttribute("fiIdSelect", fiIdSelect);
        request.setAttribute("fcCommunTypeSelect", fcCommunTypeSelect);
        request.setAttribute("fcMsgFormateIdSelect", fcMsgFormateIdSelect);
        request.setAttribute("fcMsgTypeSelect", fcMsgTypeSelect);
        return getJspPath("receive_channel_add");
    }
	
	@RequestMapping("/receiveChannelAddSubmit")  
    public String addSubmit(@RequestParam(value="pageNo",required=false,defaultValue="1") Integer pageNo,
    		@RequestParam(value="fiIdSelect",required=false) String fiIdSelect,
			   @RequestParam(value="fcCommunTypeSelect",required=false) String fcCommunTypeSelect,
			   @RequestParam(value="fcMsgFormateIdSelect",required=false) String fcMsgFormateIdSelect,
			   @RequestParam(value="fcMsgTypeSelect",required=false) String fcMsgTypeSelect,
			   @ModelAttribute("dataxReceiveChannelVO") DataxReceiveChannelVO dataxReceiveChannelVO,
			   final HttpServletRequest request, final HttpServletResponse response)  {
		LOG.debug("Into ReceiveChannelController.receiveChannelAdd");
		dataxReceiveChannelBO.add(dataxReceiveChannelVO);        
        return init(pageNo, fiIdSelect, fcCommunTypeSelect, fcMsgFormateIdSelect, fcMsgTypeSelect, request, response);
    }
	
	
	@RequestMapping("/receiveChannelEdit")  
    public String edit(@RequestParam(value="pageNo",required=false,defaultValue="1") Integer pageNo,
    		@RequestParam(value="fiIdSelect",required=false) String fiIdSelect,
			   @RequestParam(value="fcCommunTypeSelect",required=false) String fcCommunTypeSelect,
			   @RequestParam(value="fcMsgFormateIdSelect",required=false) String fcMsgFormateIdSelect,
			   @RequestParam(value="fcMsgTypeSelect",required=false) String fcMsgTypeSelect,
			   @RequestParam(value="fiId",required=false) String fiId,
			   final HttpServletRequest request, final HttpServletResponse response)  {
		LOG.debug("Into ReceiveChannelController.receiveChannelEditInit");
		DataxReceiveChannelVO dataxReceiveChannelVO = dataxReceiveChannelBO.findById(Utils.parseInt(fiId));
		request.setAttribute("dataxReceiveChannelVO", dataxReceiveChannelVO);
		
		
		Map<String, String> optionCommunTypeMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_TRANSFERSWAY);
        request.setAttribute("optionCommunTypeMap", optionCommunTypeMap);
        
        Map<String, String> optionMsgTypeMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGETYPE);
        request.setAttribute("optionMsgTypeMap", optionMsgTypeMap);
        
        Map<String, String> optionMsgFormatMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGEFORMAT);
        request.setAttribute("optionMsgFormatMap", optionMsgFormatMap);
        
        Map<String, String> optionMsgCharsetMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGECHARACTER);
        request.setAttribute("optionMsgCharsetMap", optionMsgCharsetMap);
        
        Map<String, String> optionFiFlagMap = Constants.STATE_MAP;
        request.setAttribute("optionFiFlagMap", optionFiFlagMap);
       
		
        request.setAttribute("pageNo", pageNo);  
        request.setAttribute("fiIdSelect", fiIdSelect);
        request.setAttribute("fcCommunTypeSelect", fcCommunTypeSelect);
        request.setAttribute("fcMsgFormateIdSelect", fcMsgFormateIdSelect);
        request.setAttribute("fcMsgTypeSelect", fcMsgTypeSelect);
        
        return getJspPath("receive_channel_edit");
    }
	
	
	@RequestMapping("/receiveChannelEditSubmit")  
    public String editSubmit(@RequestParam(value="pageNo",required=false,defaultValue="1") Integer pageNo,
    		@RequestParam(value="fiIdSelect",required=false) String fiIdSelect,
			   @RequestParam(value="fcCommunTypeSelect",required=false) String fcCommunTypeSelect,
			   @RequestParam(value="fcMsgFormateIdSelect",required=false) String fcMsgFormateIdSelect,
			   @RequestParam(value="fcMsgTypeSelect",required=false) String fcMsgTypeSelect,
			   @ModelAttribute("dataxReceiveChannelVO") DataxReceiveChannelVO dataxReceiveChannelVO,
			   final HttpServletRequest request, final HttpServletResponse response)  {
		LOG.debug("Into ReceiveChannelController.receiveChannelEdit");        
        dataxReceiveChannelBO.edit(dataxReceiveChannelVO);        
        return init(pageNo, fiIdSelect, fcCommunTypeSelect, fcMsgFormateIdSelect, fcMsgTypeSelect, request, response);
    }
	
	@Override
    protected String getBaseJspPath() {
        return JSP_PATH;
    }
}

